package com.zjl.quartz.test001;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.time.LocalDateTime;

// 保存在JobDataMap传递的参数
//@PersistJobDataAfterExecution//标记在 Job 类上，表示作业成功执行后，应将修改过的 JobDataMap 数据持久化保存
//@DisallowConcurrentExecution//标记在 Job 类上，指示调度器不应在同一时刻并发执行同一个作业实例
//@Service
@Slf4j
public class HelloJob extends QuartzJobBean /*implements Job*/ {
//    @Override
//    public void execute(JobExecutionContext context) throws JobExecutionException {
//        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
//        System.out.println("=========="+ LocalDateTime.now());
//    }

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

        context.getJobDetail().getJobDataMap().forEach(
                (k, v) -> log.info("param, key:{}, value:{}", k, v)
        );
        // your logics
        log.info("Hello Job执行时间: " + LocalDateTime.now());
    }
}
